<?php
namespace Vietnam\Controller;

use Think\Page;
use app\Vietnam\Controller\Base;
class PropertyController extends BaseController
{
    public function index()
    {
        $id = $this->user_info['id'];
        $data = M('user')->where('id = '.$id )->find();

        $data1 = M('reward_config')->where('id=1')->find();
        $data['all_exuu']=$data['z1']+$data['frozen_z1'];
        $data['all_usdt']=$data['z8']+$data['frozen_z8'];
        //dump($data);
         $this->assign('data',$data);
         $this->assign('data1',$data1);

        //公告
        $news=M('news')->where(array('type'=>1,'status'=>1,'language'=>3))->order('create_time desc')->find();
        $this->assign('news',$news);

//         $this->getEXUU();
//         $this->getUSDT();
         
        $this->display();

    }


    public function get_yue(){
        $this->getUSDT();
//        $this->getEXUU();
        $this->getUSDTomni();
        $user=M('user')->where(array('id'=>$this->user_info['id']))->find();
        $user['all_exuu']=$user['z1']+$user['frozn_z1'];
        $user['all_usdt']=$user['z8']+$user['frozn_z8'];
//        dump($user);
        $this->ajaxReturn($user);
    }

    public function price(){
        if(IS_POST){
            $data=I('post.type');
            $this->ajaxReturn($this->price_api($data));
        }
    }

    public function jiedian(){
        $this->display();
    }

    public function touzi(){
        $config=M('reward_config')->where('id=1')->find();
        $this->assign('config',$config);
        $usdtapi=$this->usdtapi();//usdt汇率
        $this->assign('usdtapi',$usdtapi);
        $user=M('user')->where(array('id'=>$this->user_info['id']))->find();
        if(IS_POST){
            $data=I('post.');
            if($data['coin']==1){
                if($data['number']>$user['z1']){
                    $this->ajaxReturn(array('code'=>0,'message'=>'您的EXUU余额不足'));
                }
            }
            if($data['coin']==8){
                if($data['number']>$user['z8']){
                    $this->ajaxReturn(array('code'=>0,'message'=>'您的USDT余额不足'));
                }
            }
            //查看是否是首存
            $give_number=0;
            $first_given=0;
            $is_first=M('user')->where(array('id'=>$this->user_info['id']))->getField('is_first');
            if(time()<=$config['ptr38']+86399){
                if($is_first==0){
                    if($data['coin']==1){
//                        $first_given=$data['number']*$config['ptr7']/100;//首次存币额外赠送20%
                        $first=1;//首次存币额外赠送20%
                    }else{
//                        $first_given=$data['number']*$usdtapi['rate']/$config['ptr17']*$config['ptr7']/100;//首次存币额外赠送20%
//                        $first_given=$data['number']/$config['ptr17']*$config['ptr7']/100;//首次存币额外赠送20%
                        $first=1;//首次存币额外赠送20%
                    }
//                $give_number+=$first_given;
                }
            }

            //20190805新增存币赠送活动  30%
            //查看是否在存币赠送活动期间
            if (time()>=$config['ptr47'] && time()<=$config['ptr48']+86399){
                //在活动期间
                if ($data['cun_time']==$config['ptr49']){//存币3个月才满足
                    $is_activity=1;
                }else{
                    $is_activity=0;
                }

            }else{
                $is_activity=0;
            }

            //查询内部人
            $insider=M('user')->where(array('is_insider'=>1,'status'=>1))->getField('id',true);
            //根据存币周期随机比例
            if($data['cun_time']==1){
                if(in_array($this->user_info['id'],$insider)){
                    $give_rate=rand($config['ptr22'],$config['ptr2']);//内部
                }else{
                    $give_rate=rand($config['ptr1'],$config['ptr22']);//外部
                }
//                $give_rate=rand($config['ptr1'],$config['ptr2']);
//                $give_rate=10;//测试比例
                $day=30;
            }elseif ($data['cun_time']==3){
                if(in_array($this->user_info['id'],$insider)){
                    $give_rate=rand($config['ptr23'],$config['ptr4']);
                }else{
                    $give_rate=rand($config['ptr3'],$config['ptr23']);
                }
//                $give_rate=rand($config['ptr3'],$config['ptr4']);
                $day=90;
            }elseif ($data['cun_time']==6){
                if(in_array($this->user_info['id'],$insider)){
                    $give_rate=rand($config['ptr24'],$config['ptr6']);
                }else{
                    $give_rate=rand($config['ptr5'],$config['ptr24']);
                }
//                $give_rate=rand($config['ptr5'],$config['ptr6']);
                $day=180;
            }
            $give_number+=$data['number']*$give_rate/100;//赠送数量
            if($data['coin']==8){
//                $give_number=$give_number*$usdtapi['rate']/$config['ptr17'];//存usdt送平台币(usdt汇率转换为平台币)
                $give_number=$give_number/$config['ptr17'];//存usdt送平台币(usdt汇率转换为平台币)
            }
            //日收益
            $day_profit=$give_number/$day;
            M()->startTrans();
            $res1=M('user')->where(array('id'=>$this->user_info['id']))->setDec('z'.$data['coin'],$data['number']);//扣除存币数量
            $res2=M('user')->where(array('id'=>$this->user_info['id']))->setInc('frozen_z'.$data['coin'],$data['number']);//冻结资产加上
            $deposit['uid']=$this->user_info['id'];
            $deposit['level']=$this->user_info['level'];
            $deposit['number']=$data['number'];
            $deposit['coin']=$data['coin'];
            $deposit['deposit_time']=$data['cun_time'];
            $deposit['given_rate']=$give_rate;
            $deposit['all_profit']=$give_number;
            $deposit['day_profit']=$day_profit;
            $deposit['is_first']=$first;
            $deposit['first_given']=$first_given;
            $deposit['price']=$config['ptr17'];//存币时价格
            $deposit['start_time']=time();
            $deposit['end_time']=time()+$day*24*60*60;

            //20190805
            $deposit['is_activity']=$is_activity;

            $res3=M('deposit')->add($deposit);
            if($res1&&$res2&&$res3){
                M()->commit();
                M('user')->where(array('id'=>$this->user_info['id']))->save(array('is_first'=>1));
                $this->add_fmoney($this->user_info['id'],$this->user_info['id'],$data['number'],$data['coin'],$data['coin'].'01','Đầu tư');
                $this->add_fmoney($this->user_info['id'],$this->user_info['id'],$data['number'],$data['coin'],$data['coin'].'03','Đóng băng');
                if ($is_activity==1){
                    $str=',享受存币活动到期赠送30%';
                }else{
                    $str='';
                }
                $this->ajaxReturn(array('code'=>1,'message'=>'存币成功,赠送比例为'.$give_rate.'%'.$str));
//                ajax_return(1,'存币成功');
            }else{
                M()->rollback();
                $this->ajaxReturn(array('code'=>0,'message'=>'存币失败'));
//                ajax_return(0,'存币失败');
            }
        }

        $id=$this->user_info['id'];
        $user=M('user')->where(array('id'=>$id))->find();
        $user['all_exuu']=$user['z1']+$user['frozen_z1'];
        $user['all_usdt']=$user['z8']+$user['frozen_z8'];

        $this->assign('user',$user);


        $this->display();
    }

    public function touzi_detail(){
        $uid=$this->user_info['id'];
        $config=M('reward_config')->where('id=1')->find();
        $deposit=M('deposit')->where(array('uid'=>$uid))->order('start_time desc')->select();
        foreach ($deposit as $k=>$v){
            $deposit[$k]['day_profit']=round($v['day_profit']*$v['price']/$config['ptr17'],2);//以存币的时候的价值计算释放日利息的价格的exuu
        }
        $this->assign('deposit',$deposit);
        $this->display();
    }

    public function award_detail(){
        $id=I('id');
        $info=M('lottery')->where(array('id'=>$id))->find();
        $lottery_id=$info['lottery_id'];
        $lottery_user=M('lottery_user')->where(array('lottery_id'=>$lottery_id))->distinct(true)->field('uid')->select();
        foreach ($lottery_user as $k=>$v){
            $lottery_user[$k]['username']=M('user')->where(array('id'=>$v['uid']))->getField('username');
            $lottery_user[$k]['count']=M('lottery_user')->where(array('lottery_id'=>$lottery_id,'uid'=>$v['uid']))->count('number');
        }
//        dump($lottery_user);die;
        $this->assign('lottery_user',$lottery_user);
        $this->assign('info',$info);
        $this->display();
    }


    //usdt汇率
    public function usdtapi(){
        $url = "https://api.jinse.com/v3/coin/detail?slugs=tether&_source=m";
        $btcData = $this->https_request($url);
        $btcData = json_decode($btcData, true);
        return $btcData;
    }

    function https_request($url,$data = null){
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        if (!empty($data)){
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        }
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        return $output;
    }

    public function price2(){
        $data=[];
        $data['btc']=$this->https_request1("http://api.coindog.com/api/v1/tick/Binance:btcUSDT?unit=cny");
        $data['eth']=$this->https_request1("http://api.coindog.com/api/v1/tick/Binance:ethUSDT?unit=cny");
        $data['ltc']=$this->https_request1("http://api.coindog.com/api/v1/tick/Binance:ltcUSDT?unit=cny");
        $data['eos']=$this->https_request1("http://api.coindog.com/api/v1/tick/Binance:eosUSDT?unit=cny");
//        $data['wfx']=$this->https_request1("https://api.mytokenapi.com/ticker/search?category=currency&keyword=Webflix&timestamp=1558063765845&code=15e926eac6ff75e8664ad3ca93a94a7a&platform=web_pc&v=1.0.0&language=zh_CN&legal_currency=CNY");
//        $data['btc']=$this->https_request1("http://api.coindog.com/api/v1/tick/Binance:btcUSDT?unit=cny");
        $res['btc'] = json_decode($data['btc'],true);
        $res['eth'] = json_decode($data['eth'],true);
        $res['ltc'] = json_decode($data['ltc'],true);
        $res['eos'] = json_decode($data['eos'],true);
        $res['wfx'] = json_decode($data['wfx'],true);
        echo json_encode($res);
    }

    public function wfxrecord()
    {
        $wfx=M('user')->where(array('id'=>$this->user_info['id']))->find();
        $config=M('reward_config')->where('id=1')->find();
        $this->assign('wfx',$wfx);
        $where['user_id']=$this->user_info['id'];
        $where['type']=5;
        $wfxrecord=M('money_detail')->where($where)->select();
        $this->assign('wfxrecord',$wfxrecord);
//        $this->assign('cny',round($wfx['z5']*$config['hapy'],2));
        $this->display();
    }
    public function btcrecord()
    {
        $btc=M('user')->where(array('id'=>$this->user_info['id']))->find();
        $record=M('fmoney')->where(array('user_id'=>$this->user_info['id']))->select();
        $this->assign('btc',$btc);
        $this->display();
    }
    public function ltcrecord()
    {
        $ltc=M('user')->where(array('id'=>$this->user_info['id']))->find();
        $record=M('fmoney')->where(array('user_id'=>$this->user_info['id']))->select();
        $this->assign('ltc',$ltc);
        $this->display();
    }
    public function ethrecord()
    {
        $eth=M('user')->where(array('id'=>$this->user_info['id']))->find();
        $record=M('fmoney')->where(array('user_id'=>$this->user_info['id']))->select();
        $this->assign('eth',$eth);
        $this->display();
    }
    public function usdtrecord()
    {
        $usdt=M('user')->where(array('id'=>$this->user_info['id']))->find();
        $record=M('fmoney')->where(array('user_id'=>$this->user_info['id']))->select();
        $this->assign('usdt',$usdt);
        $this->display();
    }

    //申请代理
    public function agent(){

        $config=M('reward_config')->where('id=1')->find();
        $usdtapi=$this->usdtapi();
        $this->assign('usdtapi',$usdtapi);
        $id=$this->user_info['id'];
        $xiaji=M('tj')->where(array('higher_id'=>$id,'level'=>array('gt',0)))->select();
        $deposit=M('deposit')->where(array('coin'=>8))->getField('uid',true);
        $deposit_exuu=M('deposit')->where(array('coin'=>1))->getField('uid',true);
        $sum=0;
        foreach ($xiaji as $k=>$v){
            if(in_array($v['admin_id'],$deposit)){
                $deposit_user=M('deposit')->where(array('uid'=>$v['admin_id'],'coin'=>8))->sum('number');
                $sum+=$deposit_user;
            }
        }
        $sum_exuu=0;
        foreach ($xiaji as $k=>$v){
            if(in_array($v['admin_id'],$deposit_exuu)){
                $deposit_user=M('deposit')->where(array('uid'=>$v['admin_id'],'coin'=>1))->sum('number');
                $sum_exuu+=$deposit_user;
            }
        }
//        $yeji=round($sum*$usdtapi['rate'],4)+round($sum_exuu*$config['ptr17'],4);
        $yeji=$sum+round($sum_exuu*$config['ptr17'],2);
        $this->assign('yeji',$yeji);

        $this->assign('config',$config);
        $user=M('user')->where(array('id'=>$this->user_info['id']))->find();
        $zc_exuu=$user['z1']+$user['frozen_z1'];
        $this->assign('zc_exuu',$zc_exuu);
        $this->assign('user',$user);
        $this->assign('insider',$this->user_info['is_insider']);

        $this->display();
    }

    public function sub_agent(){
        $data=I('post.');
        if($data['agent_level']==$this->user_info['agent_level']){
            $this->ajaxReturn(array('code'=>0,'message'=>'您已经是此等级的节点了'));
        }
        if($data['agent_level']<$this->user_info['agent_level']){
            $this->ajaxReturn(array('code'=>0,'message'=>'您申请的节点等级比目前的节点等级低'));
        }
        $config=M('reward_config')->find(1);
        $user=M('user')->where(array('id'=>$this->user_info['id']))->find();
        if ($user['is_insider']==1){//内部人认购
            if ($data['agent_level']==1){
                if ($user['z8']<10000){
                    $this->ajaxReturn(array('code'=>0,'message'=>'Số dư của bạn không đủ để nâng cấp độ'));
                }
            }
            if ($data['agent_level']==2){
                if ($user['z8']<50000){
                    $this->ajaxReturn(array('code'=>0,'message'=>'Số dư của bạn không đủ để nâng cấp độ'));
                }
            }
            if ($data['agent_level']==3){
                if ($user['z8']<100000){
                    $this->ajaxReturn(array('code'=>0,'message'=>'Số dư của bạn không đủ để nâng cấp độ'));
                }
            }
            if ($data['agent_level']==4){
                if ($user['z8']<200000){
                    $this->ajaxReturn(array('code'=>0,'message'=>'Số dư của bạn không đủ để nâng cấp độ'));
                }
            }
        }else{//非内部标准
            $holder=($user['z1']+$user['frozen_z1'])*$config['ptr17']+($user['z8']+$user['frozen_z8']);//持币量价值
            if ($data['agent_level']==1){
                if ($holder<10000){
                    $this->ajaxReturn(array('code'=>0,'message'=>'Số tiền giữ của bạn không đáp ứng điều kiện'));
                }
                if($data['yeji']<200000){
                    $this->ajaxReturn(array('code'=>0,'message'=>'Tổng doanh thu của bạn chưa đạt tiêu chuẩn của cấp độ này'));
                }
            }
            if ($data['agent_level']==2){
                if ($holder<20000){
                    $this->ajaxReturn(array('code'=>0,'message'=>'Số tiền giữ của bạn không đáp ứng điều kiện'));
                }
                if($data['yeji']<500000){
                    $this->ajaxReturn(array('code'=>0,'message'=>'Tổng doanh thu của bạn chưa đạt tiêu chuẩn của cấp độ này'));
                }
            }
            if ($data['agent_level']==3){
                if ($holder<50000){
                    $this->ajaxReturn(array('code'=>0,'message'=>'Số tiền giữ của bạn không đáp ứng điều kiện'));
                }
                if($data['yeji']<1000000){
                    $this->ajaxReturn(array('code'=>0,'message'=>'Tổng doanh thu của bạn chưa đạt tiêu chuẩn của cấp độ này'));
                }
            }
            if ($data['agent_level']==4){
                if ($holder<100000){
                    $this->ajaxReturn(array('code'=>0,'message'=>'Số tiền giữ của bạn không đáp ứng điều kiện'));
                }
                if($data['yeji']<2000000){
                    $this->ajaxReturn(array('code'=>0,'message'=>'Tổng doanh thu của bạn chưa đạt tiêu chuẩn của cấp độ này'));
                }
            }
        }

        $number=0;
        if($data['insider']==1){
            if($data['agent_level']==1){
                $number=10000;
            }
            if($data['agent_level']==2){
                $number=50000;
            }
            if($data['agent_level']==3){
                $number=100000;
            }
            if($data['agent_level']==4){
                $number=200000;
            }
        }
        $agent['uid']=$this->user_info['id'];
        $agent['sub_level']=$data['agent_level'];
        $agent['amount']=$number;
        $agent['create_time']=time();
        $res1=M('agent')->add($agent);

        $res2=M('user')->where(array('id'=>$this->user_info['id']))->setDec('z8',$number);
        if($res1&&$res2){
            $this->ajaxReturn(array('code'=>1,'message'=>'申请成功，等待管理员审核'));
        }else{
            $this->ajaxReturn(array('code'=>0,'message'=>'申请失败'));
        }
    }


    public function transfer(){
        if(IS_POST){
            $data=I('post.');
            $check=M('user')->where(array('username'=>$data['username']))->find();
            if(!$check){
                $this->ajaxReturn(array('code'=>0,'message'=>'不存在该用户'));
            }
            $user=M('user')->where(array('id'=>$this->user_info['id']))->find();
            if($data['coin']==1){
                if($data['amount']>$user['z1']){
                    $this->ajaxReturn(array('code'=>0,'message'=>'余额不足，重新输入'));
                }
            }
            if($data['coin']==8){
                if($data['amount']>$user['z8']){
                    $this->ajaxReturn(array('code'=>0,'message'=>'余额不足，重新输入'));
                }
            }

            if(md5($data['password'])!==$user['password2']){
                $this->ajaxReturn(array('code'=>0,'message'=>'密码错误'));
            }

            $transfer['uid']=$this->user_info['id'];
//            $transfer['uid_address']=$this->user_info['eth_address'];
            $transfer['accept_username']=$data['username'];
            $transfer['amount']=$data['amount'];
            $transfer['coin']=$data['coin'];
//            $transfer['hash']=$data['txhash'];
            $transfer['time']=time();
            $res1=M('transfer')->add($transfer);
            $res2=M('user')->where(array('id'=>$check['id']))->setInc('z'.$transfer['coin'],$data['amount']);
            $res3=M('user')->where(array('id'=>$this->user_info['id']))->setDec('z'.$transfer['coin'],$data['amount']);
            $this->add_fmoney($this->user_info['id'],$check['id'],$data['amount'],$transfer['coin'],555,'转账');
            $this->add_fmoney($check['id'],$this->user_info['id'],$data['amount'],$transfer['coin'],555,'收款');
            if($res1&&$res2&&$res3){
                $this->ajaxReturn(array('code'=>1,'message'=>'转账成功'));
            }else{
                $this->ajaxReturn(array('code'=>0,'message'=>'转账失败'));
            }

        }
        $exuu=$this->user_info['z1'];
        $this->assign('exuu',$exuu);
        $user=M('user')->where(array('id'=>$this->user_info['id']))->find();
        $this->assign('user',$user);

        $this->assign('password2',$this->user_info['password2']);
        $this->display();
    }



    //钱包首页
    public function qianbao()
    {

        //获取充提币记录
        $userid = $this->user_info['id'];

        $userinfo=M('user')->where(array('id'=>$userid))->find();

        $config=M('reward_config')->where(['id'=>1])->find();
        $this->assign('zc',$userinfo['z1']);
        $zctoCNY=round($userinfo['z1']*$config['ptr17'],4);
        $this->assign('cny',$zctoCNY);

//        $coinListData = M('coinlist')->where(['userid'=>$userid])->select();
//
//        $this->assign('coinListData', $coinListData);

        $record=M('fmoney')->where(array('user_id'=>$userid,'type'=>array('in','1,8')))->order('create_time desc')->select();
        foreach ($record as $k=>$v){
            $record[$k]['from_name']=M('user')->where(array('id'=>$v['from_id']))->getField('username');
        }
        $this->assign('record',$record);
        //$this->getBTC();
        //$this->getEth();
        $this->getUSDT();
        //$this->getWFX();
        $this->getEXUU();
        $this->getUSDTomni();
        $this->display();
    }

    //充币页面
    public function zhuanshou()
    {

        //判断是否生成钱包地址
        $userid = $this->user_info['id'];
        $userData = M('user')->where(['id'=>$userid])->find();

        $this->assign('isAddress',$userData['is_address']);

        $this->assign('coinAddress',$userData['eth_address']);

//        $this->getEXUU();

        $this->display();
    }

    //生成BTC地址

    public function btcAddress()
    {

        //判断BTC地址是否存在
        $userid = $this->user_info['id'];
        $userData = M('user')->where(['id'=>$userid])->find();

        if(!empty($userData['btc_address']))
        {
            ajax_return(1,'BTC地址已生成');
        }

        $CoinClient = CoinClient('bitcoinrpc', 'bitcoinrpc', '127.0.0.1', '8332', 5, array(), 1);

        $json = $CoinClient->getwalletinfo();

        if (!isset($json['walletversion']) || !$json['walletversion']) {
            ajax_return(1,'钱包连接失败');
        }

        //生成新的钱包地址
        $wallet_ad = $CoinClient->getnewaddress($userData['phone']);

        if (!$wallet_ad)
        {
            ajax_return(1,'生成新钱包地址失败');
        }

        $info['btc_address'] = $wallet_ad;
        $info['is_address'] = 2;


        $res = M('user')->where(['id'=>$userid])->save($info);


    }

    //生成ETH地址

    public function ethAddress()
    {
        $data = I('post.');

        //判断BTC地址是否存在
        $userid = $this->user_info['id'];

        $userData = M('user')->where(['id'=>$userid])->find();

        if(!empty($userData['eth_address']))
        {
            ajax_return(1,'ETH地址已生成');
        }
//        $coinArr=$this->auto_coin();//随机平台钱包地址
//        $info['eth_address'] = $coinArr['from'];
//        $info['eth_key'] = $coinArr['key'];
        $info['eth_address'] = $data['address'];
        $info['eth_key'] = $data['key'];
        $info['coin_time'] = time();
        $info['is_address'] = 2;


        $res = M('user')->where(['id'=>$userid])->save($info);

        if($res)
        {
            ajax_return(0,'申请成功');
        }else
        {
            ajax_return(1,'申请失败');
        }


        //ajax_return(0,'申请成功');
        //ajax_return(1,'申请失败');

    }

    public function usdtAddress(){
        //判断usdt地址是否存在
        $userid = $this->user_info['id'];
        $userData = M('user')->where(['id'=>$userid])->find();

        if(!empty($userData['usdt_address']))
        {
            ajax_return(1,'USDTOMNI地址已生成');
        }

        $CoinClient = CoinClient('usdtomni', 'usdtomni', '127.0.0.1', '60001', 5, array(), 1);

        $json = $CoinClient->getinfo();

        if ($json['version']=='{' || !$json['version'] || $json['version']=='' ) {
            ajax_return(1,'钱包连接失败');
        }

        //生成新的钱包地址
        $wallet_ad = $CoinClient->getnewaddress($userData['username']);
        //导出地址私钥
        $wallet_key = $CoinClient->dumpprivkey($wallet_ad);

        if (!$wallet_ad)
        {
            ajax_return(1,'生成新钱包地址失败');
        }

        $info['usdt_address'] = $wallet_ad;
        $info['usdt_key'] = $wallet_key;
        $info['is_address'] = 2;


        $res = M('user')->where(['id'=>$userid])->save($info);
    }

    //获取币种名称
    public function coinName()
    {
        $data = I('post.');

        $userid = $this->user_info['id'];
        $userData = M('user')->where(['id'=>$userid])->find();

//        if($data['coinname'] == 1)
//        {
//            ajax_return(0,'BTC',$userData['btc_address']);
//
//        }elseif ($data['coinname'] == 2) {
//
//            ajax_return(0,'ETH',$userData['eth_address']);
//
//        }elseif ($data['coinname'] == 3) {
//
//            ajax_return(0,'USDT',$userData['eth_address']);
//
//        }elseif ($data['coinname'] == 4) {
//
//            ajax_return(0,'WFX',$userData['eth_address']);
//
//        }

        if($data['coinname'] == 1){
            if($userData['eth_address']){
                ajax_return(0,'EXUU',$userData['eth_address']);
            }
            $info['is_address'] = 1;
            M('user')->where(['id'=>$userid])->save($info);
            ajax_return(1,'地址不存在');
        }elseif($data['coinname']==8){
            if($userData['eth_address']){
                ajax_return(0,'USDT',$userData['eth_address']);
            }
            $info['is_address'] = 1;
            M('user')->where(['id'=>$userid])->save($info);
            ajax_return(1,'地址不存在');
        }else{
            if($userData['usdt_address']){
                ajax_return(0,'USDT-OMNI',$userData['usdt_address']);
            }
            $info['is_address'] = 1;
            M('user')->where(['id'=>$userid])->save($info);
            ajax_return(1,'地址不存在');
        }

        if($data['coinname'] == 1)
        {
            $qrcode == 1;
        }else
        {
            $qrcode == 2;
        }

        $this->assign('qrcode',$qrcode);

        $this->assign('coinAddress', $coinAddress);

    }


    //BTC查询
    public function getBtc()
    {

        $userid = $this->user_info['id'];
        $userData = M('user')->where(['id'=>$userid])->find();

        $map['coinname'] = 'btc';
        $map['type'] = 1;
        $map['userid'] = $userid;

        $data = M('coinlist')->where($map)->find();

        //如果数据库不存在则去查询区块数据
        if(!$data)
        {

            $CoinClient = CoinClient('bitcoinrpc', 'bitcoinrpc', '127.0.0.1', '8332', 5, array(), 1);

            $json = $CoinClient->getwalletinfo();

            if (!isset($json['walletversion']) || !$json['walletversion'])
            {
                ajax_return(1,'钱包连接失败');
            }

            $resData = $CoinClient->listtransactions();

            //再判断区块中是否有数据
            if($resData)
            {
                //如果存在数据入库
                foreach ($resData as $k => $v)
                {
                    if($v['category'] == 'receive' && $v['label'] == $userData['phone'])
                    {
                        //交易数据入库
                        $info['userid'] = $userid;
                        $info['phone'] = $userData['phone'];
                        $info['coinname'] = 'btc';
                        $info['address'] = $v['address'];
                        $info['hash'] = $v['txid'];
                        $info['amount'] = $v['amount'];
                        $info['fee'] = 0;
                        $info['type'] = 1; //1 充币 2提币
                        $info['addtime'] = $v['time'];
                        $info['endtime'] = time();
                        $info['status'] = 1; // 1 已完成 2审核中

                        //充值记录入库
                        M('coinlist')->add($info);

                        //账户中增加余额
                        M('user')->where(['id'=>$userid])->setInc('z7', $v['amount']);
                    }
                }
            }

        }else
        {//如果数据库里不为空，再去区块里查询

            $CoinClient = CoinClient('bitcoinrpc', 'bitcoinrpc', '127.0.0.1', '8332', 5, array(), 1);

            $json = $CoinClient->getwalletinfo();

            if (!isset($json['walletversion']) || !$json['walletversion']) {
                ajax_return(1,'钱包连接失败');
            }

            $resData = $CoinClient->listtransactions();

            //再判断区块中是否有数据
            if($resData)
            {
                //如果存在数据入库
                foreach ($resData as $k => $v)
                {
                    if($v['category'] == 'receive' && $v['label'] == $userData['phone'])
                    {
                        //再判断数据是否已经插入到数据库中
                        $isempty = M('coinlist')->where(['hash'=> $v['txid']])->find();

                        if(!$isempty)
                        {
                            //交易数据入库
                            $info['userid'] = $userid;
                            $info['phone'] = $userData['phone'];
                            $info['coinname'] = 'btc';
                            $info['address'] = $v['address'];
                            $info['hash'] = $v['txid'];
                            $info['amount'] = $v['amount'];
                            $info['fee'] = 0;
                            $info['type'] = 1; //1 充币 2提币
                            $info['addtime'] = $v['time'];
                            $info['endtime'] = time();
                            $info['status'] = 1; // 1 已完成 2审核中

                            //充值记录入库
                            M('coinlist')->add($info);

                            //账户中增加余额
                            M('user')->where(['id'=>$userid])->setInc('z7', $v['amount']);
                        }
                    }
                }
            }

        }

    }

    //USDT-OMNI查询
    public function getUSDTomni()
    {

        $userid = $this->user_info['id'];
        $userData = M('user')->where(['id'=>$userid])->find();

        $map['coinname'] = 'usdtomni';
        $map['type'] = 1;
        $map['userid'] = $userid;

        $data = M('coinlist')->where($map)->find();

        //如果数据库不存在则去查询区块数据
        if(!$data)
        {

            $CoinClient = CoinClient('usdtomni', 'usdtomni', '127.0.0.1', '60001', 5, array(), 1);

            $json = $CoinClient->getinfo();

            if ($json['version']=='{' || !$json['version'] || $json['version']=='')
            {
                ajax_return(1,'钱包连接失败');
            }

            $resData = $CoinClient->omni_listtransactions('*',1000,0);

            //再判断区块中是否有数据
            if($resData)
            {
                //如果存在数据入库
                foreach ($resData as $k => $v)
                {
                    if($v['referenceaddress'] == $userData['usdt_address'] && $v['valid'] == true && $v['amount'] > 0)
                    {
                        //交易数据入库
                        $info['userid'] = $userid;
                        $info['phone'] = $userData['phone'];
                        $info['coinname'] = 'usdtomni';
                        $info['address'] = $v['referenceaddress'];
                        $info['hash'] = $v['txid'];
                        $info['amount'] = $v['amount'];
                        $info['fee'] = 0;
                        $info['type'] = 1; //1 充币 2提币
                        $info['addtime'] = $v['blocktime'];
                        $info['endtime'] = time();
                        $info['status'] = 1; // 1 已完成 2审核中

                        //充值记录入库
                        M('coinlist')->add($info);
                        //充币记录
                        $this->add_fmoney($userid,$userid,$info['amount'],8,000,'充币');

                        //账户中增加余额
                        M('user')->where(['id'=>$userid])->setInc('z8', $v['amount']);
                    }
                }
            }

        }else
        {//如果数据库里不为空，再去区块里查询

            $CoinClient = CoinClient('usdtomni', 'usdtomni', '127.0.0.1', '60001', 5, array(), 1);

            $json = $CoinClient->getinfo();

            if ($json['version']=='{' || !$json['version'] || $json['version']=='') {
                ajax_return(1,'钱包连接失败');
            }

            $resData = $CoinClient->omni_listtransactions('*',1000,0);

            //再判断区块中是否有数据
            if($resData)
            {
                //如果存在数据入库
                foreach ($resData as $k => $v)
                {
                    if($v['referenceaddress'] == $userData['usdt_address'] && $v['valid'] == true && $v['amount'] > 0)
                    {
                        //再判断数据是否已经插入到数据库中
                        $isempty = M('coinlist')->where(['hash'=> $v['txid']])->find();

                        if(!$isempty)
                        {
                            //交易数据入库
                            $info['userid'] = $userid;
                            $info['phone'] = $userData['phone'];
                            $info['coinname'] = 'usdtomni';
                            $info['address'] = $v['referenceaddress'];
                            $info['hash'] = $v['txid'];
                            $info['amount'] = $v['amount'];
                            $info['fee'] = 0;
                            $info['type'] = 1; //1 充币 2提币
                            $info['addtime'] = $v['blocktime'];
                            $info['endtime'] = time();
                            $info['status'] = 1; // 1 已完成 2审核中

                            //充值记录入库
                            M('coinlist')->add($info);
                            //充币记录
                            $this->add_fmoney($userid,$userid,$info['amount'],8,000,'充币');

                            //账户中增加余额
                            M('user')->where(['id'=>$userid])->setInc('z8', $v['amount']);
                        }
                    }
                }
            }

        }

    }


    //ETH查询
    public function getETH()
    {

        $userid = $this->user_info['id'];
        $userData = M('user')->where(['id'=>$userid])->find();

        $map['coinname'] = 'eth';
        $map['type'] = 1;
        $map['userid'] = $userid;

        $data = M('coinlist')->where($map)->find();

        //判断数据库里没有充值记录，则去区块中查询
        if(!$data)
        {

            //$userData['eth_address'] = '0xE3c78b49cfAfe43Bc62Ca149F3B7f144C59ED9E7';

            $url = "http://api.etherscan.io/api?module=account&action=txlist&address=".$userData['eth_address']."&startblock=0&endblock=99999999&sort=asc&apikey=H4R65KDWH86I2T8CD8R4ZU5TCXBAX8M7PR";

            $resUrl = requestGet($url);

            $res = json_decode($resUrl,true);

            if($res['status'] == 1 && !empty($res['result']))
            {

                foreach ($res['result'] as $k => $v)
                {

                    if($v['value'] / 1000000000000000000 > 0 && $v['to'] == strtolower($userData['eth_address']))
                    {

                        //交易数据入库
                        $info['userid'] = $userid;
                        $info['phone'] = $userData['phone'];
                        $info['coinname'] = 'eth';
                        $info['address'] = $v['to'];
                        $info['hash'] = $v['hash'];
                        $info['amount'] = $v['value'] / 1000000000000000000;
                        $info['fee'] = 0;
                        $info['type'] = 1;
                        $info['addtime'] = $v['timeStamp'];
                        $info['endtime'] = time();
                        $info['status'] = 1;

                        //充值记录入库
                        M('coinlist')->add($info);

                        //账户中增加余额
                        M('user')->where(['id'=>$userid])->setInc('z9', $v['value'] / 1000000000000000000);

                    }
                }
            }

        }
        else
        {
            //数据库中已经有充值记录，则查询区块并判断

            //$userData['eth_address'] = '0xE3c78b49cfAfe43Bc62Ca149F3B7f144C59ED9E7';

            $url = "http://api.etherscan.io/api?module=account&action=txlist&address=".$userData['eth_address']."&startblock=0&endblock=99999999&sort=asc&apikey=H4R65KDWH86I2T8CD8R4ZU5TCXBAX8M7PR";

            $resUrl = requestGet($url);

            $res = json_decode($resUrl,true);

            if($res['status'] == 1 && !empty($res['result']))
            {

                foreach ($res['result'] as $k => $v)
                {

                    if($v['value'] / 1000000000000000000 > 0 && $v['to'] == strtolower($userData['eth_address']))
                    {
                        //再判断数据是否已经插入到数据库中
                        $isempty = M('coinlist')->where(['hash'=> $v['hash']])->find();

                        if(!$isempty)
                        {
                            //交易数据入库
                            $info['userid'] = $userid;
                            $info['phone'] = $userData['phone'];
                            $info['coinname'] = 'eth';
                            $info['address'] = $v['to'];
                            $info['hash'] = $v['hash'];
                            $info['amount'] = $v['value'] / 1000000000000000000;
                            $info['fee'] = 0;
                            $info['type'] = 1;
                            $info['addtime'] = $v['timeStamp'];
                            $info['endtime'] = time();
                            $info['status'] = 1;

                            //充值记录入库
                            M('coinlist')->add($info);

                            //账户中增加余额
                            M('user')->where(['id'=>$userid])->setInc('z9', $v['value'] / 1000000000000000000);
                        }
                    }
                }
            }

        }
    }

    //USDT查询
    public function getUSDT()
    {
        $userid = $this->user_info['id'];
        $userData = M('user')->where(['id'=>$userid])->find();

        $map['coinname'] = 'usdt';
        $map['type'] = 1;
        $map['userid'] = $userid;

        $data = M('coinlist')->where($map)->find();

        //判断数据库里没有充值记录，则去区块中查询
        if(!$data)
        {

            //$userData['eth_address'] = '0xE3c78b49cfAfe43Bc62Ca149F3B7f144C59ED9E7';

            $url = "http://api.etherscan.io/api?module=account&action=tokentx&address=".$userData['eth_address']."&startblock=0&endblock=999999999&sort=asc&apikey=H4R65KDWH86I2T8CD8R4ZU5TCXBAX8M7PR";

            $resUrl = requestGet($url);

            $res = json_decode($resUrl,true);

            if($res['status'] == 1 && !empty($res['result']))
            {

                foreach ($res['result'] as $k => $v)
                {

                    if($v['value'] / 1000000 > 0 && $v['tokenSymbol'] == 'USDT' && $v['to'] == strtolower($userData['eth_address']) && $v['contractAddress'] == '0xdac17f958d2ee523a2206206994597c13d831ec7')
                    {

                        //交易数据入库
                        $info['userid'] = $userid;
                        $info['phone'] = $userData['phone'];
                        $info['coinname'] = 'usdt';
                        $info['address'] = $v['to'];
                        $info['hash'] = $v['hash'];
                        $info['amount'] = $v['value'] / 1000000;
                        $info['fee'] = 0;
                        $info['type'] = 1;
                        $info['addtime'] = $v['timeStamp'];
                        $info['endtime'] = time();
                        $info['status'] = 1;

                        //充值记录入库
                        M('coinlist')->add($info);
                        //充币记录
                        $this->add_fmoney($userid,$userid,$info['amount'],8,000,'充币');

                        //账户中增加余额
                        M('user')->where(['id'=>$userid])->setInc('z8', $v['value'] / 1000000);

                    }
                }
            }

        }

        else
        {

            //判断数据库里没有充值记录，则去区块中查询

            //$userData['eth_address'] = '0xE3c78b49cfAfe43Bc62Ca149F3B7f144C59ED9E7';

            $url = "http://api.etherscan.io/api?module=account&action=tokentx&address=".$userData['eth_address']."&startblock=0&endblock=999999999&sort=asc&apikey=H4R65KDWH86I2T8CD8R4ZU5TCXBAX8M7PR";

            $resUrl = requestGet($url);

            $res = json_decode($resUrl,true);

            if($res['status'] == 1 && !empty($res['result']))
            {

                foreach ($res['result'] as $k => $v)
                {

                    if($v['value'] / 1000000 > 0 && $v['tokenSymbol'] == 'USDT' && $v['to'] == strtolower($userData['eth_address']) && $v['contractAddress'] == '0xdac17f958d2ee523a2206206994597c13d831ec7')
                    {

                        //再判断数据是否已经插入到数据库中
                        $isempty = M('coinlist')->where(['hash'=> $v['hash']])->find();

                        if(!$isempty)
                        {

                            //交易数据入库
                            $info['userid'] = $userid;
                            $info['phone'] = $userData['phone'];
                            $info['coinname'] = 'usdt';
                            $info['address'] = $v['to'];
                            $info['hash'] = $v['hash'];
                            $info['amount'] = $v['value'] / 1000000;
                            $info['fee'] = 0;
                            $info['type'] = 1;
                            $info['addtime'] = $v['timeStamp'];
                            $info['endtime'] = time();
                            $info['status'] = 1;

                            //充值记录入库
                            M('coinlist')->add($info);
                            //充币记录
                            $this->add_fmoney($userid,$userid,$info['amount'],8,000,'充币');

                            //账户中增加余额
                            M('user')->where(['id'=>$userid])->setInc('z8', $v['value'] / 1000000);

                        }
                    }
                }
            }

        }


    }

    //WFX查询
    public function getWFX()
    {

        $userid = $this->user_info['id'];
        $userData = M('user')->where(['id'=>$userid])->find();

        $map['coinname'] = 'wfx';
        $map['type'] = 1;
        $map['userid'] = $userid;

        $data = M('coinlist')->where($map)->find();

        //判断数据库里没有充值记录，则去区块中查询
        if(!$data)
        {

            //$userData['eth_address'] = '0x61cb9627e11689d491be1b883c33280c736f38e1';

            $url = "http://api.etherscan.io/api?module=account&action=tokentx&address=".$userData['eth_address']."&startblock=0&endblock=999999999&sort=asc&apikey=H4R65KDWH86I2T8CD8R4ZU5TCXBAX8M7PR";

            $resUrl = requestGet($url);

            $res = json_decode($resUrl,true);

            if($res['status'] == 1 && !empty($res['result']))
            {

                foreach ($res['result'] as $k => $v)
                {

                    if($v['value'] / 1000000000000000000 > 0 && $v['to'] == strtolower($userData['eth_address']) && $v['contractAddress'] == '0xba1ed22c69ad00739ee2b4abd70e270be9e87ee2')
                    {

                        //交易数据入库
                        $info['userid'] = $userid;
                        $info['phone'] = $userData['phone'];
                        $info['coinname'] = 'wfx';
                        $info['address'] = $v['to'];
                        $info['hash'] = $v['hash'];
                        $info['amount'] = $v['value'] / 1000000000000000000;
                        $info['fee'] = 0;
                        $info['type'] = 1;
                        $info['addtime'] = $v['timeStamp'];
                        $info['endtime'] = time();
                        $info['status'] = 1;

                        //充值记录入库
                        M('coinlist')->add($info);

                        //账户中增加余额
                        M('user')->where(['id'=>$userid])->setInc('z5', $v['value'] / 1000000000000000000);
                    }
                }
            }
        }
        else
        {

            //判断数据库里没有充值记录，则去区块中查询

            //$userData['eth_address'] = '0x61cb9627e11689d491be1b883c33280c736f38e1';

            $url = "http://api.etherscan.io/api?module=account&action=tokentx&address=".$userData['eth_address']."&startblock=0&endblock=999999999&sort=asc&apikey=H4R65KDWH86I2T8CD8R4ZU5TCXBAX8M7PR";

            $resUrl = requestGet($url);

            $res = json_decode($resUrl,true);

            if($res['status'] == 1 && !empty($res['result']))
            {

                foreach ($res['result'] as $k => $v)
                {

                    if($v['value'] / 1000000000000000000 > 0 && $v['to'] == strtolower($userData['eth_address']) && $v['contractAddress'] == '0xba1ed22c69ad00739ee2b4abd70e270be9e87ee2')
                    {

                        //再判断数据是否已经插入到数据库中
                        $isempty = M('coinlist')->where(['hash'=> $v['hash']])->find();

                        if(!$isempty)
                        {

                            //交易数据入库
                            $info['userid'] = $userid;
                            $info['phone'] = $userData['phone'];
                            $info['coinname'] = 'wfx';
                            $info['address'] = $v['to'];
                            $info['hash'] = $v['hash'];
                            $info['amount'] = $v['value'] / 1000000000000000000;
                            $info['fee'] = 0;
                            $info['type'] = 1;
                            $info['addtime'] = $v['timeStamp'];
                            $info['endtime'] = time();
                            $info['status'] = 1;

                            //充值记录入库
                            M('coinlist')->add($info);

                            //账户中增加余额
                            M('user')->where(['id'=>$userid])->setInc('z5', $v['value'] / 1000000000000000000);
                        }
                    }
                }
            }
        }

    }


    //EXUU查询
    public function getEXUU()
    {

        $userid = $this->user_info['id'];
        $userData = M('user')->where(['id'=>$userid])->find();

        $map['coinname'] = 'exuu';
        $map['type'] = 1;
        $map['userid'] = $userid;

        $data = M('coinlist')->where($map)->find();

        //判断数据库里没有充值记录，则去区块中查询
        if(!$data)
        {

            //$userData['eth_address'] = '0xb1867cC909AdD83a09889CA393e9aF5b31f47c01';

            $url = "http://api.etherscan.io/api?module=account&action=tokentx&address=".$userData['eth_address']."&startblock=0&endblock=999999999&sort=asc&apikey=H4R65KDWH86I2T8CD8R4ZU5TCXBAX8M7PR";

            $resUrl = requestGet($url);

            $res = json_decode($resUrl,true);

            if($res['status'] == 1 && !empty($res['result']))
            {

                foreach ($res['result'] as $k => $v)
                {

                    if($v['value'] / 1000000000000000000 > 0 && $v['to'] == strtolower($userData['eth_address']) && $v['contractAddress'] == '0xa4c23a3ab707ef42c004c7e8fadf49c7448e237a')
                    {

                        //交易数据入库
                        $info['userid'] = $userid;
                        $info['phone'] = $userData['phone'];
                        $info['coinname'] = 'exuu';
                        $info['address'] = $v['to'];
                        $info['hash'] = $v['hash'];
                        $info['amount'] = $v['value'] / 1000000000000000000;
                        $info['fee'] = 0;
                        $info['type'] = 1;
                        $info['addtime'] = $v['timeStamp'];
                        $info['endtime'] = time();
                        $info['status'] = 1;

                        //充值记录入库
                        M('coinlist')->add($info);
                        //充币记录
                        $this->add_fmoney($userid,$userid,$info['amount'],1,000,'充币');

                        //账户中增加余额
                        M('user')->where(['id'=>$userid])->setInc('z1', $v['value'] / 1000000000000000000);
                    }
                }
            }
        }
        else
        {

            //判断数据库里没有充值记录，则去区块中查询

            //$userData['eth_address'] = '0xb1867cC909AdD83a09889CA393e9aF5b31f47c01';

            $url = "http://api.etherscan.io/api?module=account&action=tokentx&address=".$userData['eth_address']."&startblock=0&endblock=999999999&sort=asc&apikey=H4R65KDWH86I2T8CD8R4ZU5TCXBAX8M7PR";

            $resUrl = requestGet($url);

            $res = json_decode($resUrl,true);

            if($res['status'] == 1 && !empty($res['result']))
            {

                foreach ($res['result'] as $k => $v)
                {

                    if($v['value'] / 1000000000000000000 > 0 && $v['to'] == strtolower($userData['eth_address']) && $v['contractAddress'] == '0xa4c23a3ab707ef42c004c7e8fadf49c7448e237a')
                    {

                        //再判断数据是否已经插入到数据库中
                        $isempty = M('coinlist')->where(['hash'=> $v['hash']])->find();

                        if(!$isempty)
                        {

                            //交易数据入库
                            $info['userid'] = $userid;
                            $info['phone'] = $userData['phone'];
                            $info['coinname'] = 'exuu';
                            $info['address'] = $v['to'];
                            $info['hash'] = $v['hash'];
                            $info['amount'] = $v['value'] / 1000000000000000000;
                            $info['fee'] = 0;
                            $info['type'] = 1;
                            $info['addtime'] = $v['timeStamp'];
                            $info['endtime'] = time();
                            $info['status'] = 1;

                            //充值记录入库
                            M('coinlist')->add($info);
                            //充币记录
                            $this->add_fmoney($userid,$userid,$info['amount'],1,000,'充币');

                            //账户中增加余额
                            M('user')->where(['id'=>$userid])->setInc('z1', $v['value'] / 1000000000000000000);
                        }
                    }
                }
            }
        }

    }

    //获取账户余额
    public function getBalance()
    {
        $data = I('post.');

        //dump($data);

        $userid = $this->user_info['id'];
        $userData = M('user')->where(['id'=>$userid])->find();

//        if($data['coinname'] == 1)
//        {
//            ajax_return(0,'BTC',$userData['z7']);
//
//        }elseif ($data['coinname'] == 2) {
//
//            ajax_return(0,'ETH',$userData['z9']);
//
//        }elseif ($data['coinname'] == 3) {
//
//            ajax_return(0,'USDT',$userData['z8']);
//
//        }elseif ($data['coinname'] == 4) {
//
//            ajax_return(0,'WFX',$userData['z5']);
//        }

        if($data['coinname'] == 5)
        {
            ajax_return(0,'EXUU',$userData['z1']);

        }elseif ($data['coinname'] == 3) {

            ajax_return(0,'USDT',$userData['z8']);

        }elseif ($data['coinname'] == 10){

            ajax_return(0,'USDT-OMNI',$userData['z8']);
        }
    }

    //提币页面
    public function zhuanzhang()
    {

        $userid = $this->user_info['id'];
        $userData = M('user')->where(['id'=>$userid])->find();
        $config=M('reward_config')->find();
        if(IS_POST)
        {
            $data = I('post.');

            //验证信息是否完整
//            if($data['coinname'] == '' || $data['address'] == '' || $data['amount'] == '' || $data['password'] == '')
            if($data['coinname'] == '' || $data['address'] == '' || $data['amount'] == '')
            {
                //ajax_return(0,'申请成功');
                ajax_return(1,'提币信息不完整');
            }

            //判断地址格式
            if($data['coinname']==10){
                if (!(preg_match('/^(1|3)[a-zA-Z\d]{24,33}$/', $data['address']) && preg_match('/^[^0OlI]{25,34}$/', $data['address']))) {
                    ajax_return(1,'地址格式不正确'); //满足if代表地址不合法
                }
            }
            //短信
//            $code['mobile'] = $data['phone'];
//            $code['code'] = $data['getCode'];
            // if(!M('msg_list')->where($code)->order('id desc')->find())
            // {
            //     ajax_return(1,'验证码不正确');
            // }

            //验证支付密码
//            if(md5($data['password']) != $userData['password2']){
//                ajax_return(1,'支付密码错误');
//            }

            //判断余额是足够
            if($data['amount'] <= 0)
            {
                ajax_return(1,'提币数量不能小于等于0');
            }
            if ($data['coinname']=='5'){//exuu
                if ($data['amount']>$userData['z1']){
                    ajax_return(1,'余额不足');
                }
            }
            if ($data['coinname']=='3'){//usdt
                if ($data['amount']>$userData['z8']){
                    ajax_return(1,'余额不足');
                }
            }
            if ($data['coinname']=='10'){//exuu
                if ($data['amount']>$userData['z8']){
                    ajax_return(1,'余额不足');
                }
            }
            if(md5($data['password'])!==$userData['password2']){
                ajax_return(1,'密码错误');
            }

//            $day_money=$userData['day_money']-$data['amount'];
//            if($day_money<0){
//                ajax_return(1,'超过每日限额');
//            }
//            $day_count=$userData['day_count']-1;
//            if($config['ptr68'] < $userData['day_count']){
//                ajax_return(1,'超过每日提币次数');
//            }

            $amount=0;//总共扣除币默认为0
            $charge=0;//手续费默认为0
            $charge=$data['amount']*$config['ptr45']/100;//实际手续费
            $actual_amount=$data['amount']-$charge;//实际到账
//            if($data['coinname'] == 1)
//            {
//                //BTC2019052117
//                if ($config['ptr77'] > $data['amount'])
//                {
//                    ajax_return(1,'超过最低限额'.$config['ptr77']);
//                }
//                //手续费扣除
//                $charge=$data['amount']*$config['ptr73'];
//                $amount = $data['amount']+$charge;
////                $amount = $data['amount']*(1+$config['ptr73']);
//                if($data['amount'] > $userData['z7'])
//                {
//                    ajax_return(1,'账户余额不足');
//                }
//                //BTC
//                if ($config['ptr69'] < ($userData['day_money1']+$data['amount']))
//                {
//                    ajax_return(1,'超过每日限额');
//                }
//
//
//            }elseif ($data['coinname'] == 2) {
//                //ETH2019052117
//                if ($config['ptr78'] > $data['amount'])
//                {
//                    ajax_return(1,'超过最低限额'.$config['ptr78']);
//                }
//                //手续费扣除
//                $charge=$data['amount']*$config['ptr74'];
//                $amount = $data['amount']+$charge;
////                $amount = $data['amount']*(1+$config['ptr74']);
//                if($data['amount'] > $userData['z9'])
//                {
//                    ajax_return(1,'账户余额不足');
//                }
//                //ETH
//                if ($config['ptr70'] < ($userData['day_money2']+$data['amount']))
//                {
//                    ajax_return(1,'超过每日限额');
//                }
//
//            }elseif ($data['coinname'] == 3) {
//                //USDT2019052117
//                if ($config['ptr79'] > $data['amount'])
//                {
//                    ajax_return(1,'超过最低限额'.$config['ptr79']);
//                }
//                //手续费扣除
//                $charge=$data['amount']*$config['ptr75'];
//                $amount = $data['amount']+$charge;
////                $amount= $data['amount']*(1+$config['ptr75']);
//                if($data['amount'] > $userData['z8'])
//                {
//                    ajax_return(1,'账户余额不足');
//                }
//
//                //USDT
//                if ($config['ptr71'] < ($userData['day_money3']+$data['amount']))
//                {
//                    ajax_return(1,'超过每日限额');
//                }
//
//            }elseif ($data['coinname'] == 4) {
//                //WFX2019052117
//                if ($config['ptr80'] > $data['amount'])
//                {
//                    ajax_return(1,'超过最低限额'.$config['ptr80']);
//                }
//                //手续费扣除
//                $charge=$data['amount']*$config['ptr76'];
//                $amount = $data['amount']+$charge;
////                $amount = $data['amount']*(1+$config['ptr76']);
//                if($data['amount'] > $userData['z5'])
//                {
//                    ajax_return(1,'账户余额不足');
//                }
//                //WFX
//                if ($config['ptr72'] < ($userData['day_money4']+$data['amount']))
//                {
//                    ajax_return(1,'超过每日限额');
//                }
//            }

            //数据入库
            $info['userid'] = $userid;
            $info['phone'] = $userData['phone'];
            if($data['coinname'] == 1)
            {
                $info['coinname'] = 'btc';


            }elseif ($data['coinname'] == 2) {

                $info['coinname'] = 'eth';

            }elseif ($data['coinname'] == 3) {

                $info['coinname'] = 'usdt';

            }elseif ($data['coinname'] == 4) {

                $info['coinname'] = 'wfx';
            }elseif ($data['coinname'] == 5) {

                $info['coinname'] = 'exuu';
            }elseif ($data['coinname'] == 10){
                $info['coinname'] = 'usdtomni';
            }
//            $info['address'] = $data['address'];

//            //手续费扣除
//            $info['amount'] = $data['amount']*(1-$config['ptr76']);
//            $info['amount'] = $data['amount'];
            $info['ti_amount'] = $data['amount'];//作为提币需求字段
            $info['amount'] = $actual_amount;//作为实际到账字段
            $info['address'] = $data['address'];
            $info['fee'] = $charge;
            $info['type'] = 2;
            $info['status'] = 2;
//            $info['status'] = 1;
            $info['addtime'] = time();
//            $info['endtime'] = time();
//            $info['hash'] = $data['txhash'];

            $res1 = M('coinlist')->add($info);

//            if($data['coinname'] == 1)
//            {
//                //统计每日限额
//                $res4= M('user')->where(['id'=>$userid])->setInc('day_money1',$amount);
//                $res2 = M('user')->where(['id'=>$userid])->setDec('z7', $amount);
//
//            }elseif ($data['coinname'] == 2) {
//                //统计每日限额
//                $res4= M('user')->where(['id'=>$userid])->setInc('day_money2',$amount);
//                $res2 = M('user')->where(['id'=>$userid])->setDec('z9',$amount);
//
//            }elseif ($data['coinname'] == 3) {
//                //统计每日限额
//                $res4= M('user')->where(['id'=>$userid])->setInc('day_money3',$amount);
//                $res2 = M('user')->where(['id'=>$userid])->setDec('z8', $amount);
//
//            }elseif ($data['coinname'] == 4) {
//                //统计每日限额
//                $res4= M('user')->where(['id'=>$userid])->setInc('day_money4',$amount);
//                $res2 = M('user')->where(['id'=>$userid])->setDec('z5', $amount);
//            }elseif ($data['coinname'] == 5) {
//                //统计每日限额
//                //$res4= M('user')->where(['id'=>$userid])->setInc('day_money4',$amount);
//                $res2 = M('user')->where(['id'=>$userid])->setDec('z1', $data['amount']);
//            }
            //统计提币次数
//            $res3 = M('user')->where(['id'=>$userid])->save(['day_money'=>$day_money,'day_count'=>$day_count]);
            //$res3 = M('user')->where(['id'=>$userid])->setInc('day_count');
            if($data['coinname']==5){
                $type=1;
                $res2 = M('user')->where(['id'=>$userid])->setDec('z1', $data['amount']);
            }
            if($data['coinname']==3){
                $type=8;
                $res2 = M('user')->where(['id'=>$userid])->setDec('z8', $data['amount']);
            }
            if($data['coinname']==10){
                $type=8;
                $res2 = M('user')->where(['id'=>$userid])->setDec('z8', $data['amount']);
            }
            if($res1&&$res2)
            {
                $this->add_fmoney($userid,$userid,$data['amount'],$type,$type.'00','申请提币');
//                ajax_return(0,'申请成功');
                ajax_return(0,'提币成功，等待审核');
            }else
            {
                ajax_return(1,'申请失败');
            }

        }else
        {
            //判断是否生成钱包地址

            $this->assign('accountBalance',$userData['z1']);

            $this->assign('config',$config);
            $this->assign('userData',$userData);
            $this->display();
        }

    }







}